version 13.0
log using "C:\Users\mgolder\Dropbox\campaign_sentiment_paper\replication\data_analysis\figure5.log", replace
#delimit ;

*     ***************************************************************** *;
*     ***************************************************************** *;
*       File-Name:      figure5.do                                      *;
*       Date:           January 14, 2019                                *;
*       Author:         MRG/CC                                          *;
*       Purpose:      	Produce Figure 5 for It's Not Only What You     *;
*                       Say, It's Also How You Say It: The Strategic    *;
*                       Use Of Campaign Sentiment. Journal of Politics. *;
*                       Forthcoming.                                    *;
* 	    Input File:     sentiment.dta                                   *;
*       Output File:    figure5.log                                     *;
*       Data Output:    none                                            *;             
*       Previous file:  sentiment.dta                                   *;
*       Machine:        desktop/laptop                     				*;
*     ****************************************************************  *;
*     ****************************************************************  *;

*     ****************************************************************  *;
*        Load data                                                      *;
*     ****************************************************************  *;

use "C:\Users\mgolder\Dropbox\campaign_sentiment_paper\replication\data_analysis\sentiment.dta", clear;

set more off;

*     ****************************************************************  *;
*       Declare data to be panel, where the panel is based on language  *;
*     ****************************************************************  *;

xtset language;

xtsum positive_sentiment;

*     ****************************************************************  *;
*       Generate additional variables that we will need for our         *;
*       analysis.                                                       *;
*     ****************************************************************  *;

gen incumbent_inflation_l = incumbent*inflation_l;
label var incumbent_inflation "incumbent*inflation_l";
gen incumbent_unemployment_l = incumbent*unemployment_l;
label var incumbent_unemployment_l "incumbent*unemployment_l";
gen incumbent_pm = incumbent*pm;
label var incumbent_pm "incumbent*pm";
gen incumbent_fm = incumbent*fm;
label var incumbent_fm "incumbent*fm";
gen left_right2=left_right*left_right;
label var left_right2 "left_right*left_right";
gen extremist = 0;
replace extremist=1 if family_id ==14 | family_id==40;
replace extremist = . if family_id==.;
label var extremist "1 if communist/socialist or far right, 0 otherwise";
gen extremist2 = 0;
replace extremist2=1 if family_id ==14 | family_id==40 | family_id==19;
replace extremist2 = . if family_id==.;
label var extremist2 "1 if communist/socialist, far right, or greens, 0 otherwise";
gen extremist_inflation_l=extremist*inflation_l;
label var extremist_inflation "extremist*inflation_l";
gen extremist_unemployment_l=extremist*unemployment_l;
label var extremist_unemployment_l "extremist*unemployment_l";

tabulate language, gen(l);

*     ****************************************************************  *;
*      Change graph scheme	                                            *;
*     ****************************************************************  *;

*ssc install scheme-burd, replace;

*     ****************************************************************  *;
*     ****************************************************************  *;
*       Produce Figure 5                                                *;
*     ****************************************************************  *;
*     ****************************************************************  *;

*     ****************************************************************  *;
*     ****************************************************************  *;
*       Panel (a) Inflation                                             *;
*     ****************************************************************  *;
*     ****************************************************************  *;

sum inflation_l;
return list;
scalar standard_deviation=r(sd);
di standard_deviation;

matrix crab = J(2,2,.);
matrix coln crab = estimate se;
bootstrap, reps(400) seed(10101) cluster(election_id): xtreg positive_sentiment incumbent incumbent_pm extremist inflation_l incumbent_inflation_l, fe;

*     ****************************************************************  *;
*       For opposition parties                                          *;
*     ****************************************************************  *;

lincom inflation_l*standard_deviation;
matrix crab[1,1] = r(estimate);
matrix crab[1,2] = r(se);

*     ****************************************************************  *;
*       For incumbent parties                                           *;
*     ****************************************************************  *;

lincom (inflation_l + incumbent_inflation_l)*standard_deviation;
matrix crab[2,1] = r(estimate);
matrix crab[2,2] = r(se);

coefplot (matrix(crab[.,1]), se(crab[.,2]) offset(0) lwidth(medthick) m(smcircle) mfcolor("126 163 204") mlc("126 163 204") 
            ciop(lcolor("126 163 204"))), legend(off) 
            xtitle("") ytitle("Effect of Inflation on Positive Sentiment", size(3)) levels(95)   
            coeflabels(r1="Opposition Party" r2="Incumbent Party", wrap(18) tlcolor(black) labcolor(black) labsize(3)) grid(n) yscale(noline) 
            ylab(-0.4 -0.3 -0.2 -0.1 0 0.1 0.2, tlcolor(black) labcolor(black) labsize(2.5)) xscale(noline) yline(0, lcolor(gray)) 
            vertical scheme(burd) name(aaaaaa);

graph export "C:\Users\mgolder\Dropbox\campaign_sentiment_paper\fig5a.pdf", replace;       

*     ****************************************************************  *;
*     ****************************************************************  *;
*       Panel (b) Unemployment                                          *;
*     ****************************************************************  *;
*     ****************************************************************  *;

sum unemployment_l;
return list;
scalar standard_deviation=r(sd);
di standard_deviation;

matrix crab = J(2,2,.);
matrix coln crab = estimate se;
bootstrap, reps(400) seed(10101) cluster(election_id): xtreg positive_sentiment incumbent incumbent_pm extremist unemployment_l incumbent_unemployment_l, fe;

*     ****************************************************************  *;
*       For opposition parties                                          *;
*     ****************************************************************  *;

lincom unemployment_l*standard_deviation;
matrix crab[1,1] = r(estimate);
matrix crab[1,2] = r(se);

*     ****************************************************************  *;
*       For incumbent parties                                           *;
*     ****************************************************************  *;

lincom (unemployment_l + incumbent_unemployment_l)*standard_deviation;
matrix crab[2,1] = r(estimate);
matrix crab[2,2] = r(se);

coefplot (matrix(crab[.,1]), se(crab[.,2]) offset(0) lwidth(medthick) m(smcircle) mfcolor("126 163 204") mlc("126 163 204") 
        ciop(lcolor("126 163 204"))), legend(off) 
        xtitle("") ytitle("Effect of Unemployment on Positive Sentiment", size(3)) levels(95)   
        coeflabels(r1="Opposition Party" r2="Incumbent Party", wrap(18) tlcolor(black) labcolor(black) labsize(3)) grid(n) yscale(noline) 
        ylab(, tlcolor(black) labcolor(black) labsize(2.5)) xscale(noline) yline(0, lcolor(gray)) vertical scheme(burd) name(bbbbbb);
        
graph export "C:\Users\mgolder\Dropbox\campaign_sentiment_paper\fig5b.pdf", replace;         

gr combine aaaaaa bbbbbb;

graph export "C:\Users\mgolder\Dropbox\campaign_sentiment_paper\fig5.pdf", replace;

*     ****************************************************************  *;
*       Replication complete                                            *;
*     ****************************************************************  *;

log close;

clear;






